package com.sxbang.bms.config;

import com.sxbang.bms.config.jwt.JwtInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.ResourceUtils;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.io.File;
import java.util.List;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

	/**
	 * 跨域支持
	 * 
	 * @return
	 */
	@Bean
	public WebMvcConfigurer corsConfigurer() {
		return new WebMvcConfigurer() {
			@Override
			public void addCorsMappings(CorsRegistry registry) {
				registry.addMapping("/**").allowedMethods("*");
			}
		};
	}

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		//添加拦截器
//        registry.addInterceptor(new JwtInterceptor()).excludePathPatterns("/sign-in");
		//registry.addInterceptor(new JwtInterceptor());
		System.out.println("JWT拦截器启动");
		registry.addInterceptor(new JwtInterceptor())
				.excludePathPatterns(
						"/api/logout",
						"/error",
						"/login",
						"/",
						"/my/**",
						"/treetable-lay/**",
						"/xadmin/**")
				.addPathPatterns();
	}



}
